import { Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';

// 公共字段类，自动记录创建时间、修改时间
/* mysql中把 datetime 类型的精度不能超过 6，默认 CURRENT_TIMESTAMP */
export abstract class CommonEntity {
  @Column({ type: 'varchar', comment: '创建者', name: 'create_by', length: 64 })
  createBy: string;

  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
    name: 'create_time',
  })
  createTime: string;

  @Column({ type: 'varchar', comment: '更新者', name: 'update_by', length: 64 })
  updateBy: string;

  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
    name: 'update_time',
  })
  updateTime: string;

  setCreateBy(userName: string) {
    this.createBy = userName;
  }

  setUpdateBy(userName: string) {
    this.updateBy = userName;
  }

  setCreateTime(createTime: string) {
    this.createTime = createTime;
  }

  setUpdateTime(updateTime: string) {
    this.updateTime = updateTime;
  }
}
